package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dao.JogadorDao;
import dominio.Noticia;
import dominio.Usuario;

/**
 * Servlet implementation class VisualizarJogadorServlet
 */
public class NoticiasServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public NoticiasServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Usuario usuario = (Usuario) request.getSession().getAttribute("usuario");
		JogadorDao jd = new JogadorDao();
		List<Noticia> noticias = null;
		
		try {
			noticias = (List<Noticia>) jd.findNoticiasByJogador(usuario.getId());
		} catch (Exception e) {
			
		}
		
		String stringNoticias = "";
		for(int i=0; i<noticias.size(); i++){
			stringNoticias += noticias.get(i).getTitulo()+"&&&&"+noticias.get(i).getMsm()+"////";
		}
		response.getWriter().print(stringNoticias);
		response.getWriter().flush();
		response.getWriter().close();
	}

}
